
<template>
  <PPMPage
    v-if="pageData.length > 0"
    :formData="formData"
    @load-data="load"
    @goback="closeFun"
    @on-sumbit="submitFun"
    :pageData="pageData"
  >
  </PPMPage>
</template>
<script>
import ppmmixin from "@/mixins/ppmmixin.js";
import ppmTaskInit from "@/mixins/custorder/ppmTaskInit";
import CustOrderService from "@/api/order/CustOrderService";
import { mapState } from "vuex";
import orderSevers from "@/api/order/AendFilling";
export default {
  name: "ChangePPM",
  mixins: [ppmTaskInit, ppmmixin],
  data() {
    return {
      newcustOrder: [],
      result: [],
      formLabelWidth: "120px",
      fullscreenLoading: false,
      ppmParams: {},
      orderTask: "",
      orderTasks: {},
      newCTOInfo: [],
    };
  },
  computed: {
    ...mapState("orders", ["orderPosInfo"]),
    ...mapState("user", ["user", "busiManagerId", "custManagerId"]),
  },
  props: {
    ODKInfo: {
      type: Object,
      default: () => {
        return {};
      },
    },
    CTOInfo: {
      type: [Object, Array],
      default: () => {
        return [];
      },
    },
  },
  mounted() {
    var custOrder = JSON.parse(localStorage.getItem("custOrder_select"));
    this.newcustOrder = custOrder;

    if (this.CTOInfo instanceof Array) {
      this.newCTOInfo = this.CTOInfo;
    } else {
      this.newCTOInfo = [this.CTOInfo];
    }

    if (this.newCTOInfo.length > 0) {
      var orderItemIds = "";

      for (var i = 0; i < this.newCTOInfo.length; i++) {
        if (i == 0) {
          orderItemIds += this.newCTOInfo[i].orderItemId;
        } else {
          orderItemIds += "," + this.newCTOInfo[i].orderItemId;
        }
      }
      this.orderItemIds = orderItemIds;
    }
  },
  methods: {
    load(formData) {},
    async submitFun() {
      let base = {
        custOrderId: this.newcustOrder.custOrderId,
        custSoNumber: this.newCTOInfo[0].custSoNumber, //流水号  从上个页面带回
        custId: this.newCTOInfo[0].custId,
        orderItemIds: this.orderItemIds,
        taskId: this.ODKInfo.taskId,
        orderAuditId: this.newCTOInfo[0].orderAuditId,
        oneOrmany: "one",
        userId: "__STAFF_ID__",
        offerType: "dkyw",
        prodOfferId: this.newCTOInfo[0].prodOfferId,
        orderTasks: [
          {
            actType: "MOD",
            orderItemId: this.orderItemIds,
            taskId: this.ODKInfo.taskId,
            userName: this.user.staffName,
            userId: this.user.staffId,
            linkTel: this.formData["10461612-141000045"].value,
            taskOprDate: this.formData["10461612-100012440"].value,
            taskComment: this.formData["10461612-100012629"].value,
          },
        ],
      };

      var result = await orderSevers.saveCommonOrder(base);

      if (result.code == 200) {
        if (result.meta.resultCode == "0") {
          this.submitFunWorkItem();
        }
      }
    },
    closeFun() {
      this.$emit("close");
    },
    async submitFunWorkItem() {
      var param = {};
      param.custSoNumber = this.newCTOInfo[0].custSoNumber;
      param.processInstId = this.ODKInfo.processInstId;
      param.activityId = this.ODKInfo.activityInstId;
      // param.orderItemId = this.newCTOInfo[0].orderItemId;
      param.orderItemIds = this.orderItemIds;
      param.userId = this.user.staffId;
      param.oneOrmany = "one";
      param.taskId = this.ODKInfo.taskId;
      param.orderAuditId = this.newCTOInfo[0].orderAuditId;
      param.custId = this.newCTOInfo[0].custId;

      var result = await CustOrderService.doWorkItem(param);

      if (result.meta.resultCode == "0") {
        this.$confirm(result.meta.resultMsg, "提示", {
          confirmButtonText: "确定",
          showCancelButton: false,
          type: "success",
          center: true,
        });
        this.$emit("close");
      } else {
        this.$confirm(result.meta.resultMsg, "提示", {
          confirmButtonText: "确定",
          showCancelButton: false,
          type: "warn",
          center: true,
        });
      }
    },
  },
};
</script>
<style scoped>
</style>



